package com.weijian.controller;

import com.weijian.common.ApiResponse;
import com.weijian.dal.entity.UserSignIn;
import com.weijian.dal.entity.UserSignInStats;
import com.weijian.dal.dto.signin.SignInMonthlyRecord;
import com.weijian.service.SignInService;
import com.weijian.util.SessionUserUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 用户签到控制器
 */
@Tag(name = "用户签到管理")
@RestController
@RequestMapping("/api/signin")
@RequiredArgsConstructor
public class SignInController {

    private final SignInService signInService;

    @Operation(summary = "用户每日签到")
    @PostMapping("/daily")
    public ApiResponse<UserSignIn> dailySignIn() {
        Long userId = SessionUserUtil.getCurrentUserId();
        return signInService.dailySignIn(userId);
    }

    @Operation(summary = "查询今日签到状态")
    @GetMapping("/today-status")
    public ApiResponse<Boolean> getTodaySignStatus() {
        Long userId = SessionUserUtil.getCurrentUserId();
        return signInService.getTodaySignStatus(userId);
    }

    @Operation(summary = "获取用户签到统计")
    @GetMapping("/stats")
    public ApiResponse<UserSignInStats> getUserSignInStats() {
        Long userId = SessionUserUtil.getCurrentUserId();
        return signInService.getUserSignInStats(userId);
    }

    @Operation(summary = "获取月度签到记录")
    @GetMapping("/monthly/{year}/{month}")
    public ApiResponse<SignInMonthlyRecord> getMonthlySignInRecord(
            @PathVariable int year,
            @PathVariable int month) {
        Long userId = SessionUserUtil.getCurrentUserId();
        return signInService.getMonthlySignInRecord(userId, year, month);
    }
}